function initPage(baseInfoJson,transferDeptInfoJson){
	var basePath = $("#basePath").val();
	var medicalDepts=baseInfoJson['medicalDepts'];//科室
	$("select").each(function(){
		$(this).append("<option value=''>---请选择---</option>");
	});
	
	$(".medicalDept").each(function(){
		var options = "";
		for(var index in medicalDepts){
			var medicalDept = medicalDepts[index];
	    	options+="<option value='"+medicalDept.uniq_code+"'>"+medicalDept.label+"</option>"
	    } 
       $(this).append(options);
	});
	var transferDeptRecords=transferDeptInfoJson['transferDeptRecords'];//转科记录集合
	for(var index in transferDeptRecords){
		var transferDeptRecord = transferDeptRecords[index];
		var add_content= addTransferDeptRecord();
		add_content.find("input[name$='.transferDeptDateTime']").val(transferDeptRecord.transferDeptDateTime);
		add_content.find("input[name$='.transferDeptRemarks']").val(transferDeptRecord.transferDeptRemarks);
		if(transferDeptRecord.outDeptCode){
			var selectOption = add_content.find("select[name$='outDeptCode']").find("option[value='"+transferDeptRecord.outDeptCode+"']")
			if(selectOption.length > 0){
				selectOption.attr("selected",true);
			}else{
				add_content.find("select[name$='outDeptCode']").append("<option selected='selected' value='"+transferDeptRecord.outDeptCode+"'>"+transferDeptRecord.outDeptName+"</option>");
			}
			
		};
		add_content.find("input[name$='.outDeptName']").val(transferDeptRecord.outDeptName);
		
		if(transferDeptRecord.inDeptCode){
			var selectOption = add_content.find("select[name$='inDeptCode']").find("option[value='"+transferDeptRecord.inDeptCode+"']")
			if(selectOption.length > 0){
				selectOption.attr("selected",true);
			}else{
				add_content.find("select[name$='inDeptCode']").append("<option selected='selected' value='"+transferDeptRecord.inDeptCode+"'>"+transferDeptRecord.inDeptName+"</option>");
			}
			
		};
		add_content.find("input[name$='.inDeptName']").val(transferDeptRecord.inDeptName);
    } 
	
	var trs = $("#transferDeptRecords tbody tr");
	
	if($("#transferDeptRecords tbody tr").length <1){
		addTransferDeptRecord();
	}
	
	var validator = $("#transferDeptInfoForm").validate({
		errorElement: "title",
		submitHandler:function(form){
			var url = $(form).attr("action");
			layer.load(1,{offset: '350px'});
			/*if(url){
				return true;
			}*/
			return true;
		}
	});
}

function addTransferDeptRecord(){
	var basePath = $("#basePath").val();
	var transferDeptCountOjb = $("#transferDeptRecordCount");
	var count = parseInt(transferDeptCountOjb.val());
	var add_content=$("#templateTransferDeptTr").clone();
	add_content.removeAttr("id");
	
	add_content.find("input[name^='transferDeptRecords[0].']").each(function(){
		var eventObj = $(this);
		var name = eventObj.attr("name").replace("[0]", "["+count+"]");
		eventObj.attr("name",eventObj.attr("name").replace("[0]", "["+count+"]"));
   		
	});
	
	add_content.find("select[name^='transferDeptRecords[0].']").each(function(){
		var eventObj = $(this);
		var name = eventObj.attr("name").replace("[0]", "["+count+"]");
		eventObj.attr("name",eventObj.attr("name").replace("[0]", "["+count+"]"));
	});
	
	add_content.find("select[class='medicalDept']").each(function(){
		$(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	
	/*add_content.find("input[name='transferDeptRecords[0].transferDeptDate']").attr("name","transferDeptRecords["+count+"].transferDeptDate");
	
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagCode']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagCode").val(diseaseDiagRecord.diseaseDiagCode);;
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagName']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagName").val(diseaseDiagRecord.diseaseDiagName);;
	*/
	
	$("#transferDeptRecords tbody").append(add_content);
	transferDeptCountOjb.val(count +1);
	return add_content;
}

function deleteTransferDeptRecord(obj){
	$(obj).parent().parent().remove();
}